Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create codeql.yml #4624

Merged
merged 1 commit into from
Oct 26, 2023
Merged

Create codeql.yml #4624

merged 1 commit into from
Oct 26, 2023

Conversation

gabriellavengeo
Copy link
Contributor

@gabriellavengeo gabriellavengeo commented Oct 25, 2023

- What I did

Enable CodeQL scanning.

- How I did it

Add codeql.yml

- How to verify it

Check CodeQL Github action and code scanning results

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Oct 25, 2023

Codecov Report

Merging #4624 (39b1d37) into master (b7b5b31) will not change coverage.
Report is 10 commits behind head on master.
The diff coverage is n/a.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4624   +/-   ##
=======================================
  Coverage   59.74%   59.74%           
=======================================
  Files         288      288           
  Lines       24849    24849           
=======================================
  Hits        14846    14846           
  Misses       9117     9117           
  Partials      886      886           

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@thaJeztah
Copy link
Member

Thank you for contributing! It appears your commit message is missing a DCO sign-off,
causing the DCO check to fail.

We require all commit messages to have a Signed-off-by line with your name
and e-mail (see "Sign your work"
in the CONTRIBUTING.md in this repository), which looks something like:

Signed-off-by: YourFirsName YourLastName <[email protected]>

There is no need to open a new pull request, but to fix this (and make CI pass),
you need to amend the commit(s) in this pull request, and "force push" the amended
commit.

Unfortunately, it's not possible to do so through GitHub's web UI, so this needs
to be done through the git commandline.

You can find some instructions in the output of the DCO check (which can be found
in the "checks" tab on this pull request), as well as in the Moby contributing guide.

Steps to do so "roughly" come down to:

  1. Set your name and e-mail in git's configuration:

    git config --global user.name "YourFirstName YourLastName"
    git config --global user.email "[email protected]"

    (Make sure to use your real name (not your GitHub username/handle) and e-mail)

  2. Clone your fork locally

  3. Check out the branch associated with this pull request

  4. Sign-off and amend the existing commit(s)

    git commit --amend --no-edit --signoff

    If your pull request contains multiple commits, either squash the commits (if
    needed) or sign-off each individual commit.

  5. Force push your branch to GitHub (using the --force or --force-with-lease flags) to update the pull request.

Sorry for the hassle (I wish GitHub would make this a bit easier to do), and let me know if you need help or more detailed instructions!

@thaJeztah
Copy link
Member

Canned replies FTW 😂


on:
push:
branches: [ "master", "18.06", "18.09", "19.03", "[a-zA-Z0-9][a-zA-Z0-9].[a-zA-Z0-9]", "[a-zA-Z0-9][a-zA-Z0-9].[a-zA-Z0-9][a-zA-Z0-9]" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the 19.03 and older branches; they're no longer maintained (I may have locked them as well)

(FWIW I'm considering to use different naming schemes for release branches; release/XXX for actively maintained release branches, and archive/XXX for branches that are no longer maintained - assuming those branches contain possibly code that was not in the latest tag from the branch)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canned replies FTW 😂

Lol yes

We can remove the 19.03 and older branches; they're no longer maintained (I may have locked them as well)

Sure, let's leave it just on master! We can update it if you decide to adopt the new release branch naming convention.

@gabriellavengeo gabriellavengeo changed the title WIP:Create codeql.yml Create codeql.yml Oct 25, 2023
@gabriellavengeo gabriellavengeo marked this pull request as ready for review October 25, 2023 15:16
Comment on lines 31 to 32
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this part came from a template / example; we don't have swift in this repository, which effectively means that CodeQL now only runs on ubuntu-latest.

I guess we can remove the swift condition, or make it explicitly only run on ubuntu-latest, or if running it on different platforms improves coverage of CodeQL, perhaps we should have all of Linux, macOS, and Windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's from the auto-generated stuff, I'll clean it up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being nit-picky; I expect these kind of changes to apply to other repositories where we'll be adding CodeQL as well, so probably after we tweaked things, we can copy/pasta things to the other repositories 🤗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries at all!

Comment on lines 42 to 45
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll unlikely be adding any of the other (currently supported) languages, so perhaps we should remove this comment, also because that list may be out of date at any time in future.

The link to what's currently supported (https://aka.ms/codeql-docs/language-support) may still be useful though, so perhaps keep that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure, I'll clean up all the irrelevant autogenerated stuff

Comment on lines 64 to 42
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part feels like a lot of magic; I suspect it will just do a go build . (or along those lines), which won't match how we build our actual binaries (we may be passing specific build options).

Wondering if we can integrate this with a build-stage, and provide it access to the produced artefacts instead.

I see the lines below this outline "here's what to do if you don't want to use the auto build"

I suspect buildx and buildkit will be in a similar situation, and @crazy-max has a lot more GHA-Fu than I have; perhaps he has suggestions (and we can take a similar approach in the buildx repository - not having to reinvent the wheel)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually autobuild tries to detect build scripts and common build systems, so from the logs it look like it's using the Makefile (https://github.com/docker/cli/actions/runs/6641001271/job/18042547995?pr=4624#step:4:110)

As for giving it access to the produced build artefacts, that wouldn't do the trick as it does some tracing and instrumentation during compilation to do the extraction (https://docs.github.com/en/code-security/codeql-cli/codeql-cli-manual/database-create#-c---commandcommand). Same reason caching is an issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, right. One thing I notice at least that in that case, it builds on the host (not using the Dockerfile), and will build with a different version of Go;

2023/10/25 13:19:30 Autobuilder was built with go1.21.1, environment has go1.20.10

So we may need a go-setup action added to have the same version of Go as other workflows at least.

Do we know if the CodeQL analysis can be injected into a container somehow, so that it runs in the same environment as we'd otherwise be running in? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually, for this to work like in the example

    # Specify the container in which actions will run
    container:
      image: codeql-container:f0f91db

it would need to be an image from Hub or another configured registry, can't just give it a Dockerfile


on:
push:
branches: [ "master" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could use the same list as for the other workflows;

workflow_dispatch:
push:
branches:
- 'master'
- '[0-9]+.[0-9]+'
tags:
- 'v*'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thanks!

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a codeql workflow: https://github.com/docker/cli/blob/master/.github/workflows/codeql-analysis.yml

Could you just update this one and rename it codeql.yml?

@thaJeztah Yeah I got similar PR on login-action: docker/login-action#622

@thaJeztah
Copy link
Member

DOH! I knew we had it, but disabled at some point, so thought we removed it 🙈

@@ -1,6 +1,15 @@
name: codeql
name: "CodeQL"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as docker/login-action#622 (comment) if you don't mind 😇

codeql:
runs-on: ubuntu-20.04
analyze:
name: Analyze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Signed-off-by: Gabriela Georgieva <[email protected]>
Comment on lines 34 to 35
container:
image: 'docker-cli-dev:latest'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually you need to remove this otherwise it fails:

image

Don't think we need it for codeql

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that wasn't supposed to go into the commit - fixed!

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gabriellavengeo
Copy link
Contributor Author

@crazy-max @thaJeztah Thanks for reviewing! Don't have write access to merge it myself but feel free to do so

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the CodeQL logs and it seems codeql go extractor does not take into account our vendor.mod: https://github.com/github/codeql/blob/dbb4167f804e4b9dc5544a4a7bc19c3e4250ac2d/go/extractor/extractor.go#L221

Which could be an issue because files in vendor are interpreted as legit source code instead of dependencies which could result in false-positives for analysis. Maybe not a real issue though as I can see: https://github.com/github/codeql/blob/dbb4167f804e4b9dc5544a4a7bc19c3e4250ac2d/go/extractor/extractor.go#L200C2-L200C14

Not a CodeQL expert though so I defer 😅

@gabriellavengeo
Copy link
Contributor Author

@crazy-max yeah I think it's fine, it seems to skip them (seeing Skipping dependency package github.com/docker/cli/vendor/... in the logs)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@thaJeztah thaJeztah merged commit a6351d0 into docker:master Oct 26, 2023
76 checks passed
@thaJeztah thaJeztah added this to the 25.0.0 milestone Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants